﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SQLite;
using ManagerHmsshield;


    public class Tabela
    {
        public string NameTable;
        public DataTable dt = null;

        public Tabela(string aNameTable)
        {
            this.NameTable = aNameTable;
            dt = SQLUtils.GetDataTable(string.Format("SELECT * FROM {0}", aNameTable));
        }       

        public void refreshTable()
        {
            dt = SQLUtils.GetDataTable(string.Format("SELECT * FROM {0}", NameTable));
        }

        public DataTable SelectTable(String where)
        {
            return SQLUtils.GetDataTable(string.Format("SELECT * FROM {0} WHERE {1}", NameTable, where));
        }

        public void insert(string campos)
        {
            String values = "";
            values = values + "'" + campos.Replace("'", "''") + "',";
            values = values.Substring(0, values.Length - 1);
            string sql = string.Format("INSERT INTO {0}  VALUES ({1})", NameTable, values);
            SQLiteCommand mycommand = new SQLiteCommand(ConexaoBancoDados.ConexaoAtiva());
            mycommand.CommandText = sql;
            mycommand.ExecuteNonQuery();

            refreshTable();

        }
    }

